package com.jia.train.batch.configuration;

import com.jia.train.batch.job.DistributedQuartzJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 声明式定时调度 生产环境不使用这种
 */
//@Configuration
public class QuartzInstanceConfiguration {

    @Bean
    public JobDetail jobDetail() {
        return JobBuilder
                .newJob(DistributedQuartzJob.class)
//                .withIdentity()
                .storeDurably()
                .build();
    }


    @Bean
    public Trigger trigger() {
        return TriggerBuilder.newTrigger()
                .forJob(jobDetail())
//                .withIdentity()
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule("0/2 * * * * ?"))
                .build();

    }

}
